package io.renren.modules.bs.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.bs.entity.BsHospitalEntity;
import io.renren.modules.bs.vo.BsHospitalVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 医院表
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-13 22:35:07
 */
@Mapper
public interface BsHospitalDao extends BaseMapper<BsHospitalEntity> {

    @Select("SELECT count(1) FROM bs_hospital hosp\n" +
            "LEFT JOIN bs_department dp on dp.hospital_id = hosp.hospital_id\n" +
            "left JOIN bs_department_patient dpa ON dpa.department_id = dp.department_id\n" +
            "WHERE hosp.hospital_id = #{dataValue} AND dpa.is_leave=0")
    Integer getExtractableNumber( @Param("dataValue") Long dataValue);

    @Select("SELECT hosp.*,count(dpa.department_patient_id) available_number FROM bs_hospital hosp\n" +
            "left JOIN bs_department dep ON hosp.hospital_id = dep.hospital_id\n" +
            "left JOIN bs_department_patient dpa ON dpa.department_id = dep.department_id and dpa.is_leave=0\n" +
            "GROUP BY hosp.hospital_id")
    List<BsHospitalVo> getTreeData();
}
